#ifndef __COMMON_H__
#define __COMMON_H__

#define OFP_LOG_FILE_NAME "/usr/lib/biometric-authentication/drivers/extra/log_ofp.txt"

#define PRINT_LOG_MAX_SIZE	500


//#define _DBG_	//开启调试输出，屏蔽则关输出
//#define _ERR_	//开启错误输出，屏蔽则关输出
//#define _LOG_	//开始关键信息输出，屏蔽则关输出

#ifdef _DBG_
#define	DBG(...) printf(__VA_ARGS__)
#else
#define	DBG(...)
#endif

#ifdef _ERR_
#define	ERR(...) printf(__VA_ARGS__)
#else
#define	ERR(...)
#endif

#ifdef _LOG_
#define	LOG(...) printf(__VA_ARGS__)
#else
#define	LOG(...)
#endif

#define D_DBG(...)	\
	DBG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	DBG(__VA_ARGS__)

#define D_ERR(...)	\
	ERR("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	ERR(__VA_ARGS__)

#define D_LOG(...)	\
	LOG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	LOG(__VA_ARGS__)

extern int ofp_print_log(char *buf, int len);
extern int ofp_print_log_time(char *buf, int len);

//简单输出信息
#define W_LOG(fmt, ... ) \
	{\
		char info[PRINT_LOG_MAX_SIZE] = {0};\
		snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
		ofp_print_log(info, strlen(info));\
		LOG("%s", info);\
	}

#define W_DBG(fmt, ... ) \
	{\
		char info[PRINT_LOG_MAX_SIZE] = {0};\
		snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
		ofp_print_log(info, strlen(info));\
		DBG("%s", info);\
	}

#define W_ERR(fmt, ... ) \
		{\
			char info[PRINT_LOG_MAX_SIZE] = {0};\
			snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
			ofp_print_log(info, strlen(info));\
			ERR("%s", info);\
		}

//输出时间戳、文件、行号、函数
#define WD_LOG(fmt, ... ) \
	{\
		char msg_log[PRINT_LOG_MAX_SIZE] = {0};\
		char info[PRINT_LOG_MAX_SIZE] = {0};\
		snprintf(msg_log, PRINT_LOG_MAX_SIZE, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
		strcat(msg_log, info);\
		ofp_print_log_time(msg_log, strlen(msg_log));\
		LOG("%s", msg_log);\
	}

#define WD_ERR(fmt, ... ) \
	{\
		char msg_log[PRINT_LOG_MAX_SIZE] = {0};\
		char info[PRINT_LOG_MAX_SIZE] = {0};\
		snprintf(msg_log, PRINT_LOG_MAX_SIZE, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
		strcat(msg_log, info);\
		ofp_print_log_time(msg_log, strlen(msg_log));\
		ERR("%s", msg_log);\
	}

#define WD_DBG(fmt, ... ) \
	{\
		char msg_log[PRINT_LOG_MAX_SIZE] = {0};\
		char info[PRINT_LOG_MAX_SIZE] = {0};\
		snprintf(msg_log, PRINT_LOG_MAX_SIZE, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(info, PRINT_LOG_MAX_SIZE, fmt, ##__VA_ARGS__);\
		strcat(msg_log, info);\
		ofp_print_log_time(msg_log, strlen(msg_log));\
		DBG("%s", msg_log);\
	}




#define DRV_OK		(0)
#define DRV_ERR 	(-1)

#define uint8 unsigned char
#define int8 char

#define uint16 unsigned short int
#define int16 short int

#define uint32 unsigned int
#define int32 int



#endif

